package com.zhuozhou.jdyc.main.meinfo.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.zhuozhou.jdyc.R;
import com.zhuozhou.jdyc.api.UserAccountHelper;
import com.zhuozhou.jdyc.base.BaseActivity;
import com.zhuozhou.jdyc.databinding.ActivityConcernMerchantBinding;
import com.zhuozhou.jdyc.main.main.activity.MerchantActivity;
import com.zhuozhou.jdyc.main.meinfo.adapter.ConcernMerchantAdapter;
import com.zhuozhou.jdyc.main.meinfo.viewmodel.MeInfoViewModel;
import com.zhuozhou.jdyc.wight.recyclerview.MyLayoutManager;

/**
 * Create by Once_ChuXy on 2021/9/28
 * Describe:足迹、收藏   关注Concern
 */
public class ConcernMerchantActivity extends BaseActivity<MeInfoViewModel, ActivityConcernMerchantBinding> implements ConcernMerchantAdapter.OnItemClickListener {

    private ConcernMerchantAdapter concernMerchantAdapter;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_concern_merchant;
    }

    @Override
    public String setTitleBar() {
        return "关注店铺";
    }

    @Override
    public void initView() {

        mViewModel.BasicsMyFollowMutableLiveData.observe(this, v -> {
            if (v.getObj() == null || v.getObj().size() == 0) {
                binding.tvNoOrder.setVisibility(View.VISIBLE);
                binding.mRecyclerViewOrder.setVisibility(View.GONE);
                return;
            } else {
                binding.tvNoOrder.setVisibility(View.GONE);
                binding.mRecyclerViewOrder.setVisibility(View.VISIBLE);
                concernMerchantAdapter = new ConcernMerchantAdapter(this);
                concernMerchantAdapter.setList(v.getObj());
                concernMerchantAdapter.setOnItemClickListener(this);
                binding.mRecyclerViewOrder.setAdapter(concernMerchantAdapter);
                binding.mRecyclerViewOrder.setLayoutManager(new MyLayoutManager(this));
            }
        });
    }

    @Override
    public void initData(Bundle bundle) {
        mViewModel.getBasicsMyFollow(UserAccountHelper.getCoordinates().getLongitude(), UserAccountHelper.getCoordinates().getLatitude(), UserAccountHelper.getUserID() + "");
    }

    @Override
    public void onItemClick(View view, int position) {
        Intent in = new Intent(this, MerchantActivity.class);
        Bundle bundle = new Bundle();
        bundle.putString("id", concernMerchantAdapter.getList().get(position).getId() + "");
        in.putExtras(bundle);
        startActivity(in);
    }
}
